package com.mask.sca.auth.feign;

import com.mask.sca.auth.service.AuthService;
import com.mask.sca.core.response.ApiResponse;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequestMapping("/api/auth")
public class FeignAuthServiceImpl {

    private final AuthService authService;

    public FeignAuthServiceImpl(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("/login/password")
    public ApiResponse<Map<String, Object>> passwordLogin(@RequestBody Map<String, Object> params) {
        String username = (String) params.get("username");
        String password = (String) params.get("password");
        String loginType = (String) params.get("login_type");
        String clientId = (String) params.get("client_id");
        String clientSecret = (String) params.get("client_secret");
        return ApiResponse.success(authService.passwordLogin(username, password, loginType,clientId, clientSecret));
    }

    @PostMapping("/login/sms")
    public ApiResponse<Map<String, Object>> smsCodeLogin(@RequestBody Map<String, Object> params) {
        String mobile = (String) params.get("mobile");
        String code = (String) params.get("code");
        String clientId = (String) params.get("client_id");
        String clientSecret = (String) params.get("client_secret");
        return  ApiResponse.success(authService.smsCodeLogin(mobile, code, clientId, clientSecret));
    }

    @PostMapping("/refresh")
    public ApiResponse<Map<String, Object>> refreshToken(@RequestBody Map<String, Object> params) {
        String refreshToken = (String) params.get("refresh_token");
        String clientId = (String) params.get("client_id");
        String clientSecret = (String) params.get("client_secret");
        return  ApiResponse.success(authService.refreshToken(refreshToken, clientId, clientSecret));
    }
}